<!--登录页-->
<template>
  <div style="height: 100vh;overflow:hidden;
  background-image: linear-gradient(135deg,#1352f2,#3c82f5)">
    <el-container style="padding: 30px">
      <el-header>
        <div style="height: 50px;display: flex;overflow: hidden">
          <img alt="" height="100%" src="/imgs/login/logo1.png" style="margin-right: 50px;">
          <img alt="" height="50px" src="/imgs/login/logo2.png">
          <img alt="" height="50px" src="/imgs/login/verticalLine.png" style="margin-right: 30px">
          <span style="color: #fff;font-weight: bold;font-size: 30px;line-height: 50px">快玩桌游后台管理系统</span>
        </div>
      </el-header>
      <el-main>
        <el-row>
          <el-col :span="2"/>
          <el-col :span="12"><img alt="" src="/imgs/login/boardGame.png" height="650px"></el-col>
          <el-col :span="8">
            <el-card style="margin-top: 80px;">
              <h3 style="text-align: center;">用户登录</h3>
              <el-form label-position="top">
                <el-form-item label="用户名">
                  <el-input v-model="user.username" placeholder="请输入用户名" type="text"/>
                </el-form-item>
                <el-form-item label="密码">
                  <el-input v-model="user.password" placeholder="请输入密码" show-password type="password"
                            @keydown.enter="login"/>
                </el-form-item>
                <el-form-item>
                  <el-button style="width: 100%;" type="primary" @click="login">登录</el-button>
                </el-form-item>
              </el-form>
              <div style="text-align: center;color: #666;font-size: 14px;padding: 10px 0;">
                (体验账号:admin 密码:123456)
              </div>
            </el-card>
          </el-col>
        </el-row>
      </el-main>
    </el-container>
  </div>
</template>

<script setup>
import {ref} from "vue";
import axios from "axios";
import {ElMessage} from "element-plus";
import router from "@/router";

const user = ref({username: 'merchant01', password: '123456'});
const login = () => {
  // console.log(user.value);
  axios.post(BASE_URL + 'v1/backend/account/login', user.value)
      .then((response) => {
        // console.log(response.data);
        if (response.data.code === 2000) {
          // console.log(response);
          let userInfo = response.data.data;
          localStorage.setItem('user', JSON.stringify(userInfo));
          localStorage.setItem('jwtToken', response.headers['authorization'].split(' ')[1]);
          ElMessage.success('登录成功！');
          if (userInfo.type==='1') {
            router.push('/merchant/order');
          }

        } else {
          ElMessage.error(response.data.msg);
          user.value = {username: '', password: ''};
        }
      });
}
</script>

<style scoped>

</style>